$(function () {

    function Func() {
        // 轮播图区块
        this.banneUlItem = $('.lunbo .banner-bg ul');
        this.banneLiItems = $('.lunbo .banner-bg ul li');
        this.banneLiWidth = $('.lunbo .banner-bg ul li').width();
        this.bannerPointOl = $('.lunbo .banner-content ol');
        this.bannerPointItems = $('.lunbo .banner-content ol li');
        this.banneTimer = null;
        this.banneIndex = 0;
        this.banneCount = 0;
        this.bannerInpDestination = $('.banner-inp-destination');
        this.bannerInpName = $('.banner-inp-name');
        this.bannerInpPhone = $('.banner-inp-phone');
        this.bannerBtn = $('.banner-btn');
        // 为您推荐区块 轮播图
        this.recommendUlItem = $('.recommend .recommend-banner ul');
        this.recommendLiItems = $('.recommend .recommend-banner ul li');
        this.recommendLiWidth = $('.recommend .recommend-banner ul li').width();
        this.recommendPointOl = $('.recommend .recommend-point ol');
        this.recommendPointItems = $('.recommend .recommend-point ol li');
        this.recommendTimer = null;
        this.recommendIndex = 0;
        this.recommendCount = 0;
        // tab选项卡
        this.tabLiItem = $('.recommend .recommend-nav-right li');
        this.tabContent = $('.recommend .recommend-bottom-content');
        // 底部大图片区块
        this.customerCaseInpDestination = $('.customerCase-inp-destination');
        this.customerCaseInpName = $('.customerCase-inp-name');
        this.customerCaseInpPhone = $('.customerCase-inp-phone');
        this.customerCaseBtn = $('.customerCase-btn');
    }
    // 轮播图区块
    Func.prototype.banneAutoPlay = function () {
        var _this = this;
        this.banneTimer = setInterval(function () {
            _this.banneIndex++;
            if (_this.banneIndex > _this.banneLiItems.length - 1) {
                _this.banneIndex = 1;
                _this.banneUlItem.css('left', 0);
            }
            _this.banneUlItem.stop().animate({ left: -(_this.banneIndex * _this.banneLiWidth) + 'px' }, 1000);

            _this.banneCount++;
            if (_this.banneCount > _this.bannerPointItems.length - 1) {
                _this.banneCount = 0;
            }
            _this.bannerPointItems.eq(_this.banneCount).addClass('active').siblings().removeClass('active');
        }, 3000);
    }
    // 为您推荐区块
    Func.prototype.recommendAutoPlay = function () {
        var _this = this;
        this.recommendTimer = setInterval(function () {
            _this.recommendIndex++;
            if (_this.recommendIndex > _this.recommendLiItems.length - 1) {
                _this.recommendIndex = 1;
                _this.recommendUlItem.css('left', 0);
            }
            _this.recommendUlItem.stop().animate({ left: -(_this.recommendIndex * _this.recommendLiWidth) + 'px' }, 1000);

            _this.recommendCount++;
            if (_this.recommendCount > _this.recommendPointItems.length - 1) {
                _this.recommendCount = 0;
            }
            _this.recommendPointItems.eq(_this.recommendCount).addClass('active').siblings().removeClass('active');
        }, 3000)
    }

    Func.prototype.addEvent = function () {
        var _this = this;
        // 轮播图区块
        this.bannerPointOl.on('click', 'li', function () {
            clearInterval(_this.banneTimer);
            _this.banneIndex = $(this).index();
            _this.banneCount = $(this).index();
            _this.banneUlItem.stop().animate({ left: -($(this).index() * _this.banneLiWidth) + 'px' }, 1000);
            _this.bannerPointItems.eq($(this).index()).addClass('active').siblings().removeClass('active');
            _this.banneAutoPlay();
        })
        this.banneLiItems.on('mouseenter mouseleave', function (event) {
            var origType = event.handleObj.origType;
            if (origType == 'mouseenter') {
                clearInterval(_this.banneTimer);
            } else if (origType == 'mouseleave') {
                _this.banneAutoPlay();
            }
        })
        // 为您推荐区块
        // 轮播图
        this.recommendPointOl.on('click', 'li', function () {
            clearInterval(_this.recommendTimer);
            _this.recommendIndex = $(this).index();
            _this.recommendCount = $(this).index();
            _this.recommendUlItem.stop().animate({ left: -($(this).index() * _this.recommendLiWidth) + 'px' }, 1000);
            _this.recommendPointItems.eq($(this).index()).addClass('active').siblings().removeClass('active');
            _this.recommendAutoPlay();
        })
        this.recommendLiItems.on('mouseenter mouseleave', function (event) {
            var origType = event.handleObj.origType;
            if (origType == 'mouseenter') {
                clearInterval(_this.recommendTimer);
            } else if (origType == 'mouseleave') {
                _this.recommendAutoPlay();
            }
        })
        // tab选项卡
        this.tabLiItem.on('mouseenter', function () {
            $(this).addClass('active').siblings().removeClass('active');
            _this.tabContent.eq($(this).index()).addClass('active').siblings().removeClass('active');
        })

        this.bannerBtn.on('click', function () {
            var inp1 = _this.bannerInpDestination.val();
            var inp2 = _this.bannerInpName.val();
            var inp3 = _this.bannerInpPhone.val();
            if (inp1.length == 0) {
                alert('请填写目的地！');
                return;
            }
            if (inp2.length == 0) {
                alert('请填写正确的联系人姓名！');
                return;
            }
            if (inp3.length == 0) {
                alert('请填写正确的联系电话！');
                return;
            }
            alert('定制成功！我们将尽快与您联系！');
        })

        this.customerCaseBtn.on('click', function () {
            var inp1 = _this.customerCaseInpDestination.val();
            var inp2 = _this.customerCaseInpName.val();
            var inp3 = _this.customerCaseInpPhone.val();
            if (inp1.length == 0) {
                alert('请填写目的地！');
                return;
            }
            if (inp2.length == 0) {
                alert('请填写正确的联系人姓名！')
                return;
            }
            if (inp3.length == 0) {
                alert('请填写正确的联系电话！')
                return;
            }
            alert('定制成功！我们将尽快与您联系！')
        })
    }

    Func.prototype.init = function () {
        this.banneAutoPlay();
        this.recommendAutoPlay();
        this.addEvent();
    }
    new Func().init();

})